<template>
	　　<view class="box">
		<view class="loginBox">
			<view class="popup">
				<view class="loginMode">
					<view class="account" @click="isAccount" :class="!isshowAccount ? 'isAccMax': 'isAccMin'">账号登录
					</view>　
					　<view class="verification" @click="isVerification"
						:class="!isshowVerification ? 'isAccMax': 'isAccMin'">验证码登录</view>
				</view>
				<view v-show="isshowAccount" class="isshowBox">　
					<view class="inputBox">
						<text>账号</text>
						<input placeholder="请输入账号" placeholder-class="placeholder" maxlength="20" />
					</view>
					<view class="inputBox">
						<text>密码</text>
						<input placeholder="请输入密码" placeholder-class="placeholder" maxlength="20" />
					</view>
					<view class="agreement">
						<checkbox checked="true" color="#2979ff" style="transform:scale(0.6)" />
						<text>登录即同意用户协议</text>
					</view>
					<view @click="viewProtocol" class="denglu">登录</view>
				</view>
				<view v-show="isshowVerification" class="isshowBox">
					<view class="inputBox">
						<text>手机号</text>
						<input placeholder="请输入账号" placeholder-class="placeholder" maxlength="11" />
					</view>
					<view class="inputBox">
						<text>验证码</text>
						<input placeholder="请输入密码" placeholder-class="placeholder" maxlength="6" />
						<view class="countDownBox" @click="codeChange">
							<text style="width: 100%;text-align: center;">{{countDown?second+'秒':codeText}}</text>
						</view>
					</view>
					<view class="agreement">
						<checkbox checked="true" color="#2979ff" style="transform:scale(0.6)" />
						<text>登录即同意用户协议</text>
					</view>
					<view @click="viewProtocol" class="denglu">登录</view>
				</view>　
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				interval: null,
				mobile: '', // 手机号
				code: '', // 密码
				second: 60,
				countDown: false,
				codeText: '获取验证码', // 模拟获取验证码
				isshowAccount: true, // 默认显示账号密码登录
				isshowVerification: false, // 隐藏验证码登录
			}
		},
		onUnload() {
			clearInterval(this.interval);
		},
		methods: {
			// 点击验证码
			isVerification() {
				this.isshowAccount = false // 隐藏账号登录
				this.isshowVerification = true // 显示验证码登录
			},

			// 点击账号
			isAccount() {
				this.isshowVerification = false // 隐藏验证码登录
				this.isshowAccount = true // 显示账号登录
			},

			// 模拟获取验证码
			codeChange() {
				if (!this.countDown) {
					this.countDown = true
					var interval = setInterval(() => {
						if (this.second == 0) {
							this.countDown = false
							this.codeText = '重新获取'
							this.second = 60
							clearInterval(this.interval);
						}
						--this.second;
					}, 1000)
					this.interval = interval
				}
			}
		}
	}
</script>

<style lang="scss">
	.box {
		width: 100%;
		height: 100%;
		position: relative;

		.loginBox {
			width: 100%;
			height: 100%;
			background-color: #409EFF;
			position: fixed;
			top: 0px;
			left: 0px;

			.popup {
				width: 280px;
				height: 320px;
				background-color: #FFFFFF;
				position: absolute;
				top: 50%;
				left: 50%;
				padding: 0 25px;
				transform: translate(-50%, -50%);
				border-radius: 10px;

				.inputBox {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					height: 55px;
					font-size: 26rpx;

					text {
						width: 100rpx;
						flex-shrink: 0;
					}

					input {
						flex: 1;
						width: 100%;
						border-bottom: 1rpx solid #d6d6d6;
					}

					.placeholder {
						font-size: 24rpx;
						color: #c5c5c5;
					}

					.countDownBox {
						width: 150rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 20rpx;
						background-color: #e9f1f9;
						color: #2979FF;
						padding: 10rpx;
						border-radius: 20rpx;
					}

				}

				.agreement {
					height: 100rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 22rpx;
					color: #0f6bff;
					font-weight: bold;
					text-decoration: underline;
				}

				.loginMode {
					width: 300px;
					height: 31px;
					margin-top: 36px;
					margin-bottom: 20px;

					// 控制切换登录时的样式
					.isAccMax {
						font-size: 15px;
						margin-top: 6px;
						color: #D3D3D3;
					}

					.isAccMin {
						font-size: 18px;
						font-weight: 600;
						margin-top: 3px;
					}

					.account,
					.verification {
						width: 140px;
						height: 33px;
						display: inline-block;
						text-align: center;
					}
				}

				.denglu {
					border-radius: 50rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #FFFFFF;
					width: 100%;
					height: 100rpx;
					background-color: #409eff;
				}
			}
		}
	}
</style>

